package com.edu.control;

import com.edu.javaBean.Department;

import com.edu.service.DeptService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RestController
public class DeptController {
    @Autowired
    private DeptService deptService;


    @RequestMapping("/getAllDepts")
    public List<Department> getDept(@RequestBody Map<String,String> map){
       System.out.println("关键字"+map.get("keywords"));
       return deptService.getAllDepts(map.get("keywords"));
   }

   @RequestMapping(value="/addDept",method= RequestMethod.POST)

    public Map<String,Object> addDept(@RequestBody Department Dept){
       System.out.println(Dept);
       Map<String,Object> map=new HashMap<>();
       int i=deptService.addDept(Dept);
       if(i>0){
           map.put("msg","科室添加成功");
       }else{
           map.put("msg","科室添加失败");
       }
        return map;
   }

   @RequestMapping(value="/updateDept",method=RequestMethod.POST)
    public Map<String,Object> updateDept(@RequestBody Department dept){
        Map<String,Object> map=new HashMap<>();
       int i=deptService.updateDept(dept);
       if(i>0){
           map.put("msg","科室修改成功");
       }else{
           map.put("msg","科室修改失败");
       }
       return map;
   }

    @RequestMapping(value="/deleteDeptById",method=RequestMethod.POST)
    public Map<String,Object> deleteDeptById(@RequestParam int id){
        Map<String,Object> map=new HashMap<>();
        int i=deptService.deleteDeptById(id);
        if(i>0){
            map.put("msg","科室删除成功");
        }else{
            map.put("msg","科室删除失败");
        }
        return map;
    }

}
